package cn.agiledata.bank.common.tag;

import java.util.List;

import javax.servlet.jsp.JspException;

import org.apache.struts.taglib.bean.WriteTag;

import cn.agiledata.bank.hibernateBean.AccountBank;

public class BankCardNumTag extends WriteTag{
	private String inputId;
	


	public String getInputId() {
		return inputId;
	}



	public void setInputId(String inputId) {
		this.inputId = inputId;
	}



	public String formatValue(Object v)throws JspException{
		List list = (List)v;
		StringBuffer sb = new StringBuffer();
		sb.append("<span id='BankCardNum'></span>");
		sb.append(" <script> ");
		sb.append(" var array = new Array(); ");
		for(int i=0;i<list.size();i++) {
			AccountBank ab = (AccountBank)list.get(i);
			sb.append(" array['").append(ab.getId().toString()).append("']")
			  .append("='").append(ab.getAccountId()).append("';");
		}
		sb.append("	function BankCardNum(value) {document.getElementById('BankCardNum').innerText = array[value];}");
		sb.append("document.getElementById('"+inputId+"').onchange=function(){ BankCardNum(document.getElementById('"+inputId+"').value); };");
		sb.append(" if(document.getElementById('BankCardNum').innerText == '') {BankCardNum(document.getElementById('"+inputId+"').value);} ");
		sb.append(" if(document.getElementById('BankCardNum').innerText == 'undefined') {document.getElementById('BankCardNum').innerText = '';} ");
		sb.append(" </script> ");
		return super.formatValue(sb.toString());
		
			
	}


	

}
